// Ace编辑器配置文件
import ace from 'ace-builds'

// 导入必要的模块
import 'ace-builds/src-noconflict/mode-lua'
import 'ace-builds/src-noconflict/theme-monokai'
import 'ace-builds/src-noconflict/theme-github'
import 'ace-builds/src-noconflict/theme-terminal'
import 'ace-builds/src-noconflict/ext-language_tools'
import 'ace-builds/src-noconflict/ext-searchbox'

// 设置ace-builds的基础路径 - 使用CDN或本地路径
// 在开发环境中，webpack会处理这些模块的加载
ace.config.set('basePath', 'https://cdn.jsdelivr.net/npm/ace-builds@1.43.2/src-noconflict/')
ace.config.set('modePath', 'https://cdn.jsdelivr.net/npm/ace-builds@1.43.2/src-noconflict/')
ace.config.set('themePath', 'https://cdn.jsdelivr.net/npm/ace-builds@1.43.2/src-noconflict/')
ace.config.set('workerPath', 'https://cdn.jsdelivr.net/npm/ace-builds@1.43.2/src-noconflict/')

// 默认编辑器配置
export const defaultConfig = {
    mode: 'ace/mode/lua',
    theme: 'ace/theme/monokai',
    fontSize: 14,
    showPrintMargin: true,
    printMarginColumn: 80,
    showGutter: true,
    highlightActiveLine: true,
    enableBasicAutocompletion: true,
    enableLiveAutocompletion: true,
    enableSnippets: true,
    showLineNumbers: true,
    tabSize: 2,
    wrap: false,
    readOnly: false
}

// 主题配置
export const themes = [
    { name: '暗色主题', value: 'ace/theme/monokai' },
    { name: '亮色主题', value: 'ace/theme/github' },
    { name: '终端主题', value: 'ace/theme/terminal' }
]

// Lua代码补全配置
export const luaCompletions = [
    {
        caption: 'function',
        snippet: 'function ${1:name}(${2:args})\n\t${3:-- body}\nend',
        meta: 'snippet'
    },
    {
        caption: 'if',
        snippet: 'if ${1:condition} then\n\t${2:-- body}\nend',
        meta: 'snippet'
    },
    {
        caption: 'for',
        snippet: 'for ${1:i} = ${2:1}, ${3:10} do\n\t${4:-- body}\nend',
        meta: 'snippet'
    },
    {
        caption: 'while',
        snippet: 'while ${1:condition} do\n\t${2:-- body}\nend',
        meta: 'snippet'
    },
    {
        caption: 'local',
        snippet: 'local ${1:variable} = ${2:value}',
        meta: 'snippet'
    }
]